﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;

namespace Update
{
    public partial class update_menu : Form
    {
        public update_menu()
        {
            InitializeComponent();
        }
        string AppPath = System.Windows.Forms.Application.StartupPath;
        SqlConnecitonClass sqlbaglanti = new SqlConnecitonClass();

        private void Form1_Load(object sender, EventArgs e)
        {

            string old_versiyon="0";
            if (File.Exists("" + AppPath + "\\VERSIYON.INI"))
            {
                StreamReader sr = File.OpenText("" + AppPath + "\\VERSIYON.INI");
                old_versiyon = Convert.ToString(sr.ReadLine());  //1 SATIR                
                sr.Close();
            }
            else
            {
                MessageBox.Show("VERSIYON.INI BULUNAMADI "); Close();
            }
            
            this.Hide();
            string versiyon_yeni_exe =  Convert.ToString(sqlbaglanti.CommScalar("SELECT dbo.tk_par_var(0,0)", CommandType.Text));
            if (versiyon_yeni_exe == old_versiyon)
            {
                System.Diagnostics.Process.Start(""+AppPath+"\\Gemciler_Uretim.exe");
                Close();
                Application.Exit();

            }
            else
            {
                guncelle();
                timer1.Enabled = true;
                progressBar1.Minimum = 1;
                progressBar1.Maximum = 1000;
                progressBar1.Value = 100;

            }

           
         
           
        }
        private void guncelle()
        {
            Process process = new Process();

            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError = true;
            process.StartInfo.CreateNoWindow = true;
         
           
            process.StartInfo.FileName = ""+AppPath+"\\UPDATE.BAT";
            //   process.StartInfo.Arguments = "" + dosya_yolu + "";
            // process.StartInfo.WorkingDirectory = @"C:\windows\system32";
            // MessageBox.Show("SS");
            process.Start();
 


           


          
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            progressBar1.Value = progressBar1.Value+100;
            if (progressBar1.Value > 990)
            {
                timer1.Enabled = false;
                MessageBox.Show("GÜNCELLEME İŞLEMİ TAMAMLANDI");
                System.Diagnostics.Process.Start("" + AppPath + "\\Gemciler_Uretim.exe");
                Close();
                Application.Exit();
               
            }
        }
    }
}
